package com.laf.manage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.laf.manage.domain.po.Point;
import com.laf.manage.domain.vo.PointVO;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.laf.common.utils.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

import com.laf.manage.mapper.mp.PointMapper;

import com.laf.manage.service.IPointService;

/**
 * 点位管理Service业务层处理
 *
 * @author zian
 * @date 2024-10-30
 */
@Service
public class PointServiceImpl extends ServiceImpl<PointMapper, Point> implements IPointService {

    @Autowired
    private PointMapper pointMapper;

    /**
     * 查询点位管理列表
     *
     * @param point 点位管理
     * @return 点位管理
     */
    @Override
    public List<PointVO> selectPointList(Point point)
    {
        List<PointVO> pointList = pointMapper.selectPointList(buildQueryWrapper(point));
        return pointList;
    }


    private LambdaQueryWrapper<Point> buildQueryWrapper(Point query) {
        LocalDateTime beginTime = query.getBeginTime();
        LocalDateTime endTime = query.getEndTime();
        LambdaQueryWrapper<Point> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(query.getPointName()), Point::getPointName, query.getPointName());
        lqw.orderByDesc(Point::getCreateTime);
        lqw.between(beginTime != null && endTime != null, Point::getCreateTime, beginTime, endTime);
        return lqw;
    }

}
